package dao

import (
	"context"
	"gorm.io/gorm"
	"user_srv/internal/config"
	"user_srv/model"
)

type ChatMessageDao struct {
	db *gorm.DB
	c  config.Config
}

func NewChatMessageDao(db *gorm.DB, c config.Config) *ChatMessageDao {
	return &ChatMessageDao{db: db, c: c}
}

func (dao *ChatMessageDao) SavePair(ctx context.Context, sid uint64, user, ai string) error {
	return model.SavePair(ctx, dao.db, sid, user, ai)
}

func (dao *ChatMessageDao) List(ctx context.Context, sid uint64) ([]model.ChatMessages, error) {
	return model.List(ctx, dao.db, sid)
}

func (dao *ChatMessageDao) Talk(ctx context.Context, sid uint64, userInput string) (string, error) {
	// 把 dao.c 透传给 model.Talk
	conf := struct {
		TongYi struct {
			Url, Model, ApiKey string
		}
	}{}
	conf.TongYi.Url = dao.c.TongYi.Url
	conf.TongYi.Model = dao.c.TongYi.Model
	conf.TongYi.ApiKey = dao.c.TongYi.ApiKey

	return model.Talk(ctx, dao.db, conf, sid, userInput)
}
